﻿package mortal.game.view.guildNew.mercenary
{
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import fl.controls.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.guildNew.data.*;
    import mortal.game.view.guildNew.mercenary.item.*;
    import mortal.mvc.core.*;

    public class GuildNewMercenaryOperPanel extends GSprite
    {
        protected var _bg:ScaleBitmap;
        protected var _unitDes:GTextFiled;
        protected var _timesDes:GTextFiled;
        protected var _ownDes:GTextFiled;
        protected var _timesTxt:GTextFiled;
        protected var _addBtn:GLoadingButton;
        protected var _getRwBtn:GLoadingButton;
        protected var _getBg:ScaleBitmap;
        protected var _getDes:GTextFiled;
        protected var _inputBg:ScaleBitmap;
        protected var _getCoin:GBitmap;
        protected var _getTxt:GTextFiled;
        protected var _inputNum:NoBgInput;
        protected var _coinBm:GBitmap;
        protected var _coinDes:GTextFiled;
        protected var _tBm:GBitmap;
        protected var _changeDes:GTextFiled;

        public function GuildNewMercenaryOperPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.bg(0, 0, 389, 117, this, ImagesConst.PanelBg);
            this._unitDes = UIFactory.gTextField("" + Language.getString(71536), 47, 41, 100, 25, this, GlobalStyle.textFormatPutong.setColor(15721648).setSize(14));
            this._timesDes = UIFactory.gTextField("" + Language.getString(71537), 48, 6, 100, 25, this, GlobalStyle.textFormatPutong.setColor(15721648).setSize(14));
            this._ownDes = UIFactory.gTextField("" + Language.getString(71538), 48, 78, 100, 25, this, GlobalStyle.textFormatPutong.setColor(15721648).setSize(14));
            this._timesTxt = UIFactory.gTextField("", 119, 8, 100, 25, this, GlobalStyle.textFormatPutong.setColor(15721648));
            this._addBtn = UIFactory.gLoadingButton(ImagesConst.guildNewMercenaryAddBtn_upSkin, 271, 35, 110, 33, this);
            this._addBtn.label = "";
            this._getRwBtn = UIFactory.gLoadingButton(ImagesConst.guildNewMercenaryGetBtn_upSkin, 271, 73, 110, 33, this);
            this._getRwBtn.label = "";
            this._getBg = UIFactory.bg(117, 78, 149, 26, this, ImagesConst.PanelBg);
            this._getDes = UIFactory.gTextField("" + Language.getString(71539), 121, 77, 40, 25, this, GlobalStyle.textFormatPutong.setColor(15721648).setSize(14));
            this._inputBg = UIFactory.bg(119, 42, 145, 24, this, ImagesConst.InputBg);
            this._getCoin = UIFactory.gBitmap(ImagesConst.Jinbi, 242, 81, this);
            this._getTxt = UIFactory.gTextField("123465456", 160, 78, 92, 20, this, GlobalStyle.textFormatPutong.setColor(15721648).setSize(14));
            this._inputNum = UIFactory.getUICompoment(NoBgInput, 161, 43, this);
            this._coinBm = UIFactory.gBitmap(ImagesConst.Jinbi, 243, 44, this);
            this._coinDes = UIFactory.gTextField(Language.getString(71539), 120, 40, 50, 25, this, GlobalStyle.textFormatPutong.setColor(15721648).setSize(14));
            this._tBm = UIFactory.gBitmap(ImagesConst.guildNewMercenaryAddT, 9, 0, this);
            this._changeDes = UIFactory.gTextField("" + Language.getString(71540), 57, 59, 100, 20, this, GlobalStyle.textFormatHong.setSize(11));
            this._inputNum.restrict = "0-9";
            this._inputNum.setSize(80, 21);
            this._inputNum.drawNow();
            this._inputNum.maxChars = 5;
            this._inputNum.defaultText = "1000";
            this._addBtn.configEventListener(MouseEvent.CLICK, this.onSelfAdd);
            this._getRwBtn.configEventListener(MouseEvent.CLICK, this.onGetRwHd);
            this.setBtn(this._addBtn, false);
            this.setBtn(this._getRwBtn, false);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bg = null;
            this._unitDes = null;
            this._timesDes = null;
            this._ownDes = null;
            this._timesTxt = null;
            this._addBtn = null;
            this._getRwBtn = null;
            this._getBg = null;
            this._getDes = null;
            this._inputBg = null;
            this._getCoin = null;
            this._getTxt = null;
            this._inputNum = null;
            this._coinBm = null;
            this._coinDes = null;
            this._tBm = null;
            this._changeDes = null;
            super.disposeImpl(param1);
            return;
        }// end function

        public function updateTimes() : void
        {
            var _loc_4:SGuildMercenary = null;
            this._inputNum.editable = true;
            this._inputNum.mouseEnabled = true;
            this._inputNum.mouseChildren = true;
            this.setBtn(this._addBtn, true);
            var _loc_1:* = Cache.instance.guild.selfGuildInfo.mercenaryArr;
            var _loc_2:* = Cache.instance.role.entityInfo.entityId.id;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_1.length)
            {
                
                _loc_4 = _loc_1[_loc_3];
                if (_loc_4.playerId == _loc_2)
                {
                    this._inputNum.text = "" + _loc_4.money;
                    this._timesTxt.text = _loc_4.count + "/" + GuildNewMercenaryProcessor.oneDayTimes + Language.getString(71534);
                    if (this.isNextDay(_loc_4))
                    {
                        var _loc_5:Boolean = true;
                        this._inputNum.mouseEnabled = true;
                        this._inputNum.editable = _loc_5;
                        this._inputNum.mouseChildren = true;
                        this.setBtn(this._addBtn, true);
                    }
                    else if (this.notPassTime(_loc_4))
                    {
                        var _loc_5:Boolean = false;
                        this._inputNum.mouseEnabled = false;
                        this._inputNum.editable = _loc_5;
                        this._inputNum.mouseChildren = false;
                        this.setBtn(this._addBtn, false);
                    }
                    break;
                }
                _loc_3++;
            }
            this._changeDes.visible = this._inputNum.editable;
            return;
        }// end function

        private function isNextDay(param1:SGuildMercenary) : Boolean
        {
            if (param1 == null)
            {
                return false;
            }
            var _loc_2:* = param1.creatdt.time - 24 * 3600 * 1000;
            var _loc_3:* = new Date(_loc_2);
            var _loc_4:* = ClockManager.instance.nowDate;
            return _loc_3.date != _loc_4.date;
        }// end function

        private function notPassTime(param1:SGuildMercenary) : Boolean
        {
            if (param1 == null)
            {
                return false;
            }
            var _loc_2:* = ClockManager.instance.nowDate;
            var _loc_3:* = (param1.creatdt.time - _loc_2.time) / 1000;
            return _loc_3 > 0;
        }// end function

        private function setBtn(param1:Button, param2:Boolean) : void
        {
            if (param2)
            {
                param1.enabled = true;
                param1.filters = null;
            }
            else
            {
                param1.enabled = false;
                param1.filters = [FilterConst.colorFilter2];
            }
            return;
        }// end function

        public function updateRwInfo() : void
        {
            this._getTxt.text = "" + Cache.instance.guild.selfGuildInfo.mercenaryMoney;
            if (Cache.instance.guild.selfGuildInfo.mercenaryMoney == 0)
            {
                this.setBtn(this._getRwBtn, false);
            }
            else
            {
                this.setBtn(this._getRwBtn, true);
            }
            return;
        }// end function

        private function onSelfAdd(event:MouseEvent) : void
        {
            var _loc_2:* = int(this._inputNum.text);
            if (_loc_2 == 0)
            {
                MsgManager.showRollTipsMsg("" + Language.getString(71541));
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(GuildNewLocalEvent.GuildNewMercenaryAddIn, _loc_2));
            return;
        }// end function

        private function onGetRwHd(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(GuildNewLocalEvent.GuildNewMercenaryGetRw));
            return;
        }// end function

    }
}
